#include <iostream>
#include <vector>
using namespace std;

class Solution {
   public:
    int maxSubArray(vector<int>& nums) {
        vector<int> dp;
        int res = nums[0];
        for (int n : nums) {
            if (dp.empty()) {
                dp.push_back(n);
            } else {
                int add;
                if (n > n + dp.back()) {
                    add = n;
                } else {
                    add = dp.back() + n;
                }
                dp.push_back(add);
                res = max(res, add);
            }
        }
        return res;
    }
};
int main() {
    Solution s;
    vector<int> v;
    v.push_back(1);
    v.push_back(2);

    cout << s.maxSubArray(v) << endl;

    return 0;
}
